
/**
 * @author wangC
 * @create 2020-06-18 下午10:31
 * @Description   synchronized
 **/
public class Synchronized_0 {

    //同步和非同步方法是否可以同时调用? yes
    public synchronized void m1() {
        System.out.println(Thread.currentThread().getName() + " m1 start");
        try {
            Thread.sleep(10000);

        } catch (InterruptedException e) {
            e.printStackTrace();

        }
        System.out.println(Thread.currentThread().getName() + " m1 end");

    }

    public void m2() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();

        }
        System.out.println(Thread.currentThread().getName() + " m2");
    }

    public synchronized void m3() {
        System.out.println(Thread.currentThread().getName() + " m3 start");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();

        }
        System.out.println(Thread.currentThread().getName() + " m3");
    }


    public static void main(String[] args) {
        Synchronized_0 sync = new Synchronized_0();

        //同步和非同步方法是否可以同时调用
        new Thread(sync::m1, "m1").start();
        new Thread(sync::m2, "m2").start();
        //同步和同步方法是否可以同时调用?
        //new Thread(sync::m3, "m3").start();


    }
}
